package megrez.job.xxljob.jobhandler;

import java.time.Duration;

import org.springframework.stereotype.Component;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;

import lombok.extern.slf4j.Slf4j;
import megrez.job.common.Nap;

/**
 * 简单任务示例（Bean模式）
 *  
 * @author Lucky Yang
 * @since 2.6.9
 */
@Slf4j
@Component
public class DemoBean {
    @XxlJob(value = "demoBean", init = "init", destroy = "destroy")
    public void execute() {
        XxlJobHelper.log("XXL-JOB, DemoBean.");

        for (int i = 0; i < 5; i++) {
            Nap.after(Duration.ofSeconds(i)).doThis(d -> XxlJobHelper.log("beat at:" + d.toSeconds()));
        }
    }

    public void init(){
        log.info("init");
    }
    public void destroy(){
        log.info("destroy");
    }    
}
